<?php

/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/**
 * Description of Template
 *
 * @author zelic
 */
class Template {

    var $templatePath;

    public function __construct($templatePath = "") {
        $this->templatePath = $templatePath;
    }

    public function setTemplatePath($templatePath) {
        $this->templatePath = $templatePath;
    }

    public function render($templateTree, $templatePath = "") {
        //Check if there's a template
        if ($templatePath == "") {
            if ($this->templatePath == "") {
                return false;
            } else {
                $templatePath = $this->templatePath;
            }
        }
        if (file_exists($templatePath)) {
            $content = file_get_contents($templatePath);
            $templateTree->render($content);
            return $templateTree;
        } else if (file_exists("../app/view/".$templatePath)) {
            $templatePath = "../app/view/".$templatePath;
            $content = file_get_contents($templatePath);
            $templateTree->render($content);
            return $templateTree;
        } else {
            Loader::loadClass("Logger");
            Logger::error("Template is not found!");
        }
    }

}

?>
